package com.gxa.order.listener;


import com.gxa.order.eums.OrderStatusEnum;
import com.gxa.order.service.OrderService;
import com.gxa.order.pojo.PayLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = "tx-topic",
        consumerGroup = "tx-pay-group",
        selectorExpression = "*",
        consumeMode = ConsumeMode.CONCURRENTLY
)
@Slf4j
public class PayListener implements RocketMQListener<PayLog> {

    @Reference
    private OrderService orderService;

    @Override
    public void onMessage(PayLog payLog) {

        log.info("接收到消息:{}",payLog);

         //注意处理重复消费
        orderService.updateOrderStatus(payLog.getOutTradeNo(), OrderStatusEnum.PAYMENT.getCode());

    }

}
